<?php

$username = $_POST['username'];
$password = $_POST['password'];

include("opendb.php");
include("functions.php");
$res = isValidUser($username,$password);
if($res!=1) {
echo "$username = $password";
exit;
}

$Proptype = "";
$Streetdir="";
$Streetname="";
$Streetnum="";
$Streetsuffix="";
$Unit="";
$City="";
$County="";
$State="";
$Zip="";
$Longitude="";
$Latitude="";
$Price="";
$Listdate="";
$SoldDate="";
$Beds="";
$Bathsfull="";
$Bathshalf="";
$Bathstotal="";
$Sqft="";
$Parking="";
$Stories="";
$ML_Number="";
$Description="";
$Style = "";
$Yearbuilt="";
$HOA="";
$Title="";
$VT = "";
$Landing_Page="";
$FSBO="";
$Website = "";
$IVR = "";
$Status = "";
$ListingID = $_POST['ListingID'];
$Proptype=$_POST['prop_type'];
$Streetdir=$_POST['street_direction'];
$Streetnum=$_POST['street_number'];
$Streetname=$_POST['street_name'];
$Streetsuffix=$_POST['street_suffix'];
$Unit=$_POST['unit'];
$City=$_POST['city'];
$County=$_POST['county'];
$State=$_POST['state'];
$Zip=$_POST['zip'];
$Price=$_POST['price'];
$HOA=$_POST['hoa'];
$ListDate=$_POST['listdate'];
$SoldDate=$_POST['solddate'];
$Beds=$_POST['beds'];
$Bathsfull=$_POST['baths_full'];
$Bathshalf=$_POST['baths_half'];
$Bathstotal=$_POST['baths_total'];
$Sqft=$_POST['sqft'];
$Parking=$_POST['parking'];
$Stories=$_POST['stories'];
$ML_Number=$_POST['ml_number'];
$Description=$_POST['description'];
$Style=$_POST['style'];
$Yearbuilt=$_POST['yearbuilt'];
$Listingagent=$_POST['listing_agent'];
$Listingcompany=$_POST['listing_company'];
$Title=$_POST['title'];
$VT = $_POST['vt'];
$Landing_Page=$_POST['landing_page'];
$FSBO=$_POST['fsbo'];
$Website = $_POST['website'];
$IVR = $_POST['ivr'];
$Status = $_POST['status'];



// get lat lof

		$q = $q = $Streetnum." ".$Streetname. ", " . $_POST["city"]. " " . $_POST["state"]. " " . $_POST["zip"];
		$base = $PHP_SELF . "?address=" . $q ;
		$filler = "http://rpc.geocoder.us/service/csv?address=" . (urlencode($q));
		$gm = fopen($filler,"r");
		$tmp = fgetcsv($gm,8000);
		fclose($gm);
		$la = $tmp["0"];
		$lo = $tmp["1"];
		$Longitude="";
		$Latitude="";
		
		if(is_numeric($la))
		{
			$Longitude=$la;
			$Latitude=$lo;
				
		}
	
	$insertquery = "update PROPERTIES set ";
	$insertquery = $insertquery." PROPTYPE='".$Proptype."',";
	$insertquery = $insertquery." STREETDIR='".$Streetdir."',";
	$insertquery = $insertquery." STREETNAME='".$Streetname."',";
	$insertquery = $insertquery." STREETNUM='".$Streetnum."',";
	$insertquery = $insertquery." STREETSUFFIX='".$Streetsuffix."',";
	$insertquery = $insertquery." UNITFLOORNUM='".$Unit."',";
	$insertquery = $insertquery." CITY='".$City."',";
	$insertquery = $insertquery." STATE='".$State."',";
	$insertquery = $insertquery." ZIPCODE='".$Zip."',";	
	
	//switched
	$insertquery = $insertquery." LONGITUDE='".$Latitude."',";	
	$insertquery = $insertquery." LATITUDE='".$Longitude."',";	
	$insertquery = $insertquery." LISTPRICE='".$Price."',";	
	$insertquery = $insertquery." ASSOCFEE='".$HOA."',";
	$insertquery = $insertquery." LISTDATE='".$ListDate."',";	
	$insertquery = $insertquery." OFFMARKETDATE='".$SoldDate."',";		
	$insertquery = $insertquery." BEDS='".$Beds."',";	
	$insertquery = $insertquery." BATHSFULL='".$Bathsfull."',";	
	$insertquery = $insertquery." BATHSHALF='".$Bathshalf."',";	
	$insertquery = $insertquery." BATHSTOTAL='".$Bathstotal."',";	
	$insertquery = $insertquery." SQFTTOTAL='".$Sqft."',";	
	$insertquery = $insertquery." PARKINGCOVERED='".$Parking."',";
	$insertquery = $insertquery." STORIES='".$Stories."',";	
	$insertquery = $insertquery." MLSNUM='".$ML_Number."',";
	$insertquery = $insertquery." REMARKS='".$Description."',";	
	$insertquery = $insertquery." LISTING_AGENT='".$Listingagent."',";
	$insertquery = $insertquery." LISTING_COMPANY='".$Listingcompany."',";		
	$insertquery = $insertquery." STYLE='".$Style."',";
	$insertquery = $insertquery." LANDING_PAGE='".$Landing_Page."',";
	$insertquery = $insertquery." VIRTUAL_TOUR_URL='".$VT."',";
	$insertquery = $insertquery." TITLE='".$Title."',";
	$insertquery = $insertquery." FSBO='".$FSBO."',";
	$insertquery = $insertquery." IVR='".$IVR."',";
	$insertquery = $insertquery." LISTSTATUS='".$Status."',";
	
	$insertquery = $insertquery." YEARBUILT='".$Yearbuilt."',";
	if ($_POST["visible"])
	$insertquery = $insertquery." VISIBLE='1'";
	else
	$insertquery = $insertquery." VISIBLE='0'";
	
	$insertquery = $insertquery." where OID=".$ListingID;	
	
	//echo $insertquery;
	
	mysql_query($insertquery) or die(mysql_error()); 
	
	
	
	//delete the current property features, and then refill
	$dsql = "DELETE from Prop_Features where Listing_ID = '".$ListingID."'";
	$dresult = mysql_query($dsql) or die ("SQL Error".mysql_error());
	
	$kfs = explode("~",$_POST['kitchen_features']);
	
		for($i=0;$i<sizeof($kfs);$i++)
		{
           if($kfs[$i]!="") {
			$ksql = "insert into Prop_Features (Listing_ID, Type, Feature) Values ('".$ListingID."','Kitchen','".$kfs[$i]."')";
			$kresult = mysql_query($ksql) or die ("SQL Error".mysql_error());
			}
		}
	
	
	$ifs = explode("~",$_POST['interior_features']);
	
		for($i=0;$i<sizeof($ifs);$i++)
		{
			if($ifs[$i]!="") {
			$ksql = "insert into Prop_Features (Listing_ID, Type, Feature) Values ('".$ListingID."','Interior','".$ifs[$i]."')";
			$kresult = mysql_query($ksql) or die ("SQL Error".mysql_error()); 
			}
		}
	
	
	
	$efs = explode("~",$_POST['exterior_features']);
	
		for($i=0;$i<sizeof($efs);$i++)
		{
			 if($efs[$i]!="") {
			$ksql = "insert into Prop_Features (Listing_ID, Type, Feature) Values ('".$ListingID."','Exterior','".$efs[$i]."')";
			$kresult = mysql_query($ksql) or die ("SQL Error".mysql_error());
			}
		}
	
	
	
	
	$message = "The listing information has been updated successfully. <br>";
	echo "1";



?>